package band.wukong.practice.javase.core.regex;

/**
 * Description: 正则表达式
 * Author: jsun
 * Date: 2009-10-26 22:31:12
 */
public class SomeRegex {
    private static final String REGEX_NUM_DIGIT_11 = "\\d{11}";                             //11位数字
    private static final String REGEX_NUM_DIGIT_11_START_WHITH_1 = "1\\d{10}";              //1开头的11位数字
    private static final String REGEX_NUM_DIGIT_11_OR_12_START_WHITH_0 = "0\\d{10,11}";     //1开头的11位数字
    private static final String REGEX_NUM_10_OR_16 = "[+-]?[0-9]+|0[Xx][0-9A-Fa-f]+";

    private static final String REGEXP_FILE_TXT = ".*.txt";    //以.txt结尾的任意长度的字符串
    private static final String REGEXP_EMAIL = "[\\w[.-]]+@[\\w[.-]]+\\.[\\w]+";    //EMAIL

    public static void main(String[] args) {
        someRegExpTest();
        someUsefuRegExp();
    }

    private static void someRegExpTest() {
        System.out.println("扯淡".matches("..")); //任意的两位字符
        System.out.println("123.txt".matches(REGEXP_FILE_TXT));
        System.out.println("c:\\dir1\\dir2\\name.txt".matches(REGEXP_FILE_TXT));
        System.out.println("a$sdf".matches(REGEXP_FILE_TXT));
        System.out.println("abc".matches(REGEXP_FILE_TXT));

        System.out.println("i 520 u".replaceAll("\\d", "love"));    //替换所有数字为制定字符串

        System.out.println("amz".matches("[a-z]{3}"));  //内容为a-z的长度为3的字符串

    }

    private static void someUsefuRegExp() {
        String msisdn = "13705165201";
        System.out.println(msisdn.matches(REGEX_NUM_DIGIT_11));
        System.out.println(msisdn.matches(REGEX_NUM_DIGIT_11_START_WHITH_1));
        System.out.println(msisdn.matches(REGEX_NUM_DIGIT_11_OR_12_START_WHITH_0));

        System.out.println("antijapan@gmail.com".matches(REGEXP_EMAIL));
    }

}
